package com.hwtx.protocol.dubbo.code;

import com.hzgj.bcl.soa.util.Bytes;

/**
 * Created by warning on 2016/11/4.
 */
public class DubboConstants {
    public static final String DUBBO_PROTOCOL = "dubbo";
    public static final String MESSAGE_HEADER_DUBBO_ATTACHMENT = "message.header.dubbo.attachment";
    public static final String MESSAGE_HEADER_DUBBO_TRACEID = "traceId";
    public static final String MESSAGE_HEADER_DUBBO_WHOIM = "whoIm";
    public static final String MESSAGE_HEADER_DUBBO_BIZID = "bizId";


    public static final String GROUP_KEY = "group";
    public static final String VERSION_KEY = "version";
    public static final String INTERFACE_KEY = "interface";

    public static final byte RESPONSE_WITH_EXCEPTION = 0;

    public static final byte RESPONSE_VALUE = 1;

    public static final byte RESPONSE_NULL_VALUE = 2;

    /**
     * ok.
     */
    public static final byte OK = 20;

    /**
     * clien side timeout.
     */
    public static final byte CLIENT_TIMEOUT = 30;

    /**
     * server side timeout.
     */
    public static final byte SERVER_TIMEOUT = 31;

    /**
     * request format error.
     */
    public static final byte BAD_REQUEST = 40;

    /**
     * response format error.
     */
    public static final byte BAD_RESPONSE = 50;

    /**
     * service not found.
     */
    public static final byte SERVICE_NOT_FOUND = 60;

    /**
     * service error.
     */
    public static final byte SERVICE_ERROR = 70;

    /**
     * internal server error.
     */
    public static final byte SERVER_ERROR = 80;


    protected static final int HEADER_LENGTH = 16;
    // magic header.
    protected static final short MAGIC = (short) 0xdabb;
    protected static final byte MAGIC_HIGH = Bytes.short2bytes(MAGIC)[0];
    protected static final byte MAGIC_LOW = Bytes.short2bytes(MAGIC)[1];

    // message flag.
    protected static final byte FLAG_REQUEST = (byte) 0x80;
    protected static final byte FLAG_TWOWAY = (byte) 0x40;
    protected static final byte FLAG_EVENT = (byte) 0x20;
    protected static final int SERIALIZATION_MASK = 0x1f;


    public static final byte RESPONSE_OK = 20;
}
